#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
void Swap(int* x, int* y)
{
	int tmp = *x;
	*x = *y;
	*y = tmp;
}
void SelectSort(int* arr, int n)
{
	int begin = 0, end = n - 1;
	while (begin < end)
	{
		int mini = begin, maxi = begin;
		for (int i = begin + 1; i <= end; i++)
		{
			if (arr[maxi] < arr[i])
			{
				maxi = i;
			}
			if (arr[mini] > arr[i])
			{
				mini = i;
			}
		}
		Swap(&arr[mini], &arr[begin]);
		if (begin == maxi)
			maxi = mini;
		Swap(&arr[maxi], &arr[end]);
		end--;
		begin++;
	}
}
int main()
{
	int arr[] = { 3,5,1,6,8,9,0,7,2,4 };
	SelectSort(arr, 10);
	for (int i = 0; i < 10; i++)
	{
		printf("%d ", arr[i]);
	}
	return 0;
}